<!--
 * @Description: 构建表单的字段
 * @ComposerRequire: 
 * @ComposerRemove: 
 * @Author: 阿海 <764882431@qq.com>
 * @Date: 2021-05-18 11:43:00
 * @LastEditTime: 2021-07-09 15:14:36
 * @LastEditors: 阿海
-->

<script>
    
    //构建选项
    function builderFormItems(resData){
  
        var http = new Request({token_url:api.token_url,async:false,token_store_name:'form'}),webConfig = http.request('get',web_require_url+"?action=config"),html = "",layout = "layui-col-xs-offset0 layui-col-sm-offset0 layui-col-md-offset0 layui-col-lg-offset0 layui-col-space0 layui-col-lg12 layui-col-md12 layui-col-sm12 layui-col-xs12";
        
        for(var i = 0; i < resData.form_items.length; i++){
            var verify = "";
            if(resData.form_items[i].verify != ""){
                    verify = '<font style="color:red">*</font>';
                }
            var tips = "";    
            if(resData.form_items[i].tips != ""){
                tips = '<div class="layui-form-mid layui-word-aux builder-tips">'+resData.form_items[i].tips+'</div>';
            }    
            switch(resData.form_items[i].type){
                case 'text':
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><input type="text" name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" placeholder="'+resData.form_items[i].placeholder+'" autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" value="'+resData.form_items[i].value+'" '+resData.form_items[i].extra_attr+'>'+tips+'</div></div>';
                    break;
                case 'password':
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><input type="password" name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" placeholder="'+resData.form_items[i].placeholder+'" autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" value="'+resData.form_items[i].value+'" '+resData.form_items[i].extra_attr+'><a href="javascript:;" class="show-pwd-'+i+'" style="font-size: 18px;top: 10px;position: absolute;color:#666;right: 15px;"><i class="fa fa-eye"></i></a>'+tips+'</div></div>';
                    html += '<script>$(".show-pwd-'+i+'").on("click",function(){if($(this).children("i").hasClass("fa-eye")){$(this).prev("input").attr("type","text");$(this).children("i").removeClass("fa-eye");$(this).children("i").addClass("fa-eye-slash")}else{$(this).prev("input").attr("type","password");$(this).children("i").removeClass("fa-eye-slash");$(this).children("i").addClass("fa-eye")}});<\/script>'
                    break;    
                case 'textarea':
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><textarea name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" placeholder="'+resData.form_items[i].placeholder+'" autocomplete="off" class="layui-textarea '+resData.form_items[i].extra_class+'" '+resData.form_items[i].extra_attr+'>'+resData.form_items[i].value+'</textarea>'+tips+'</div></div>';
                    break;
                case 'hidden':
                    html += '<input type="hidden" name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" value="'+resData.form_items[i].value+'" >';
                    break; 
                case 'tag':
                    html += '<div id="tags" class="layuiadmin-mb-15 tags_'+resData.form_items[i].name+' tags '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><input type="text" name=""  placeholder="'+resData.form_items[i].placeholder+'" id="inputTags-'+i+'" autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" '+resData.form_items[i].extra_attr+'><input type="hidden" name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" id="tags-value-'+i+'"  value="">'+tips+'</div></div>';
                    //标签组件
                    html += '<script>$("#tags-value-'+i+'").val("'+resData.form_items[i].value+'");layui.use(["inputTags"],function(){ var inputTags = layui.inputTags;var value_'+i+' = inputTags.render({ elem:"#inputTags-'+i+'",del_tag:".tags_'+resData.form_items[i].name+'",content: "'+resData.form_items[i].value+'" != ""?("'+resData.form_items[i].value+'").split("'+resData.form_items[i].delimiter+'"):new Array(),prohibits:("'+resData.form_items[i].prohibits+'").split("'+resData.form_items[i].delimiter+'"), aldaBtn: false,/**是否开启获取所有数据的按钮*/ done: function(value,content){ $("#tags-value-'+i+'").val(content.join("'+resData.form_items[i].delimiter+'"));},delete:function(val,content){$("#tags-value-'+i+'").val(content.join("'+resData.form_items[i].delimiter+'"));}}) }) <\/script>';
                    break;     
                case 'cron':
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><input type="text" id="cron-'+i+'" name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" placeholder="'+resData.form_items[i].placeholder+'" autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" value="'+resData.form_items[i].value+'" '+resData.form_items[i].extra_attr+'>'+tips+'</div></div>';
                     //任务组件
                    html += '<script>layui.use(["cron"],function(){ var cron = layui.cron;cron.render({elem: "#cron-'+i+'", /**绑定元素*/run: "'+resData.form_items[i].url+'", /** “运行”-的接口*/ done: function(cronStr) {},});})<\/script>';
                    break;  
                case 'colorPicker':
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><input type="text" id="color_picker_'+resData.form_items[i].name+'" name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" placeholder="'+resData.form_items[i].placeholder+'" autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" value="'+resData.form_items[i].value+'" style="width:50%;height:34px;float:left;" '+resData.form_items[i].extra_attr+'> <div class="layui-inline" style="left: -1px;"><div id="colorpicker_'+i+'" class="layui-inline"></div> </div>'+tips+'</div></div>';
                    html += '<script> layui.use(["colorpicker"],function(){ var $ = layui.$,colorpicker = layui.colorpicker;colorpicker.render({elem: "#colorpicker_'+i+'", color: "'+resData.form_items[i].value+'" , alpha: '+resData.form_items[i].alpha+', predefine: true, format: '+resData.form_items[i].alpha+'?\'rgb\':\'hex\', size: "xs" , done: function (color) { $("#color_picker_'+resData.form_items[i].name+'").val(color);}, change: function (color) { }});  });$("#color_picker_'+resData.form_items[i].name+'").on("input",function(e){$("#colorpicker_'+i+' .layui-colorpicker-trigger-span").css("background",$("#color_picker_'+resData.form_items[i].name+'").val());});<\/script>';
                    break;
                case 'icon':
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><div class="layui-inline layui-icon-choose" title="点我，选择图标"  id="choose-'+i+'" style="left: 1px;float:left;"><i class="'+resData.form_items[i].value+'" title="点我，选择图标"></i></div><input type="text" name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" placeholder="'+resData.form_items[i].placeholder+'" autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'"  id="input-'+i+'"  value="'+resData.form_items[i].value+'" style="width:50%;height:34px;float:left;" '+resData.form_items[i].extra_attr+' readonly><div class="layui-inline layui-icon-clear" id="clear-'+i+'" title="点我，清除图标" style="left: -1px;"> <i class="layui-icon layui-icon-close"title="点我，清除图标"></i></div>'+tips+'</div></div>';
                    //图标选择器--解决on绑定多个使用时存在事件重复点击问题，使用one()代替on()
                    html += '<script>$(function(){$("#clear-'+i+'").on("click",function(e){$("#input-'+i+'").val("");$("#choose-'+i+'").children("i").attr("class","")});$("#choose-'+i+'").on("click",function(){layui.use(["layer","element"],function(){var layer=layui.layer;layer.open({type:1,skin:"layui-layer-lan",closeBtn:2,title:"图标选择器",area:["60%","86%"],btn:"",content:$("#icons-list"),success:function(layero,index){$(".search-icons-list").addClass("search-icons-'+i+'");$(".all-icons-list").addClass("all-icons-'+i+'")}});$(".search-icons-'+i+'").one("click","li",function(e){var new_icon=$(this).children("i").attr("class");$("#input-'+i+'").val(new_icon);$("#choose-'+i+'").children("i").attr("class",new_icon);$(".search-icons-list").removeClass("search-icons-'+i+'");layer.closeAll()});$(".all-icons-'+i+'").one("click","li",function(e){var new_icon=$(this).children("i").attr("class");$("#input-'+i+'").val(new_icon);$("#choose-'+i+'").children("i").attr("class",new_icon);$(".all-icons-list").removeClass("all-icons-'+i+'");layer.closeAll()})})});})<\/script>';
                        
                    break; 
                //省市区    
                case 'address':
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name.join("|")]==undefined?layout:resData.layout[resData.form_items[i].name.join("|")])+'" id="area-picker-'+i+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><div class="layui-input-inline" style="width: 200px;"><select name="'+((resData.form_items[i].name[0] == undefined)?"province":resData.form_items[i].name[0])+'" title="'+resData.form_items[i].title+'" class="province-selector" data-value="'+((resData.form_items[i].value[0] == undefined)?"":resData.form_items[i].value[0])+'" lay-filter="province-'+i+'"></select></div><div class="layui-input-inline" style="width: 200px;"><select name="'+((resData.form_items[i].name[1] == undefined)?"city":resData.form_items[i].name[1])+'" title="'+resData.form_items[i].title+'" class="city-selector" data-value="'+((resData.form_items[i].value[1] == undefined)?"":resData.form_items[i].value[1])+'" lay-filter="city-'+i+'"></select></div><div class="layui-input-inline" style="width: 200px;"><select name="'+((resData.form_items[i].name[2] == undefined)?"county":resData.form_items[i].name[2])+'" title="'+resData.form_items[i].title+'" class="county-selector" data-value="'+((resData.form_items[i].value[2] == undefined)?"":resData.form_items[i].value[2])+'" lay-filter="county-'+i+'"></select></div>'+tips+'</div></div>';
                    html += '<script>layui.use(["layer","form","layarea"],function(){var layer=layui.layer,form=layui.form,layarea=layui.layarea;layarea.render({elem:"#area-picker-'+i+'",data: {province: "'+((resData.form_items[i].value[0] == undefined)?"":resData.form_items[i].value[0])+'",city: "'+((resData.form_items[i].value[1] == undefined)?"":resData.form_items[i].value[1])+'",county: "'+((resData.form_items[i].value[2] == undefined)?"":resData.form_items[i].value[2])+'",province_placeholder:"--选择省--", city_placeholder:"--选择省--",county_placeholder:"--选择区--"},change:function(res){}})});<\/script>';
                    break; 
                //只显示省份    
                case 'province':
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name.join("|")]==undefined?layout:resData.layout[resData.form_items[i].name.join("|")])+'" id="area-picker-'+i+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><div class="layui-input-inline" style="width: 200px;"><select name="'+((resData.form_items[i].name[0] == undefined)?"province":resData.form_items[i].name[0])+'" title="'+resData.form_items[i].title+'" class="province-selector" data-value="'+((resData.form_items[i].value[0] == undefined)?"":resData.form_items[i].value[0])+'" lay-filter="province-'+i+'"></select></div><div class="layui-input-inline" style="width: 200px;display:none"><select name="'+((resData.form_items[i].name[1] == undefined)?"city":resData.form_items[i].name[1])+'" title="'+resData.form_items[i].title+'" class="city-selector" data-value="'+((resData.form_items[i].value[1] == undefined)?"":resData.form_items[i].value[1])+'" lay-filter="city-'+i+'"></select></div><div class="layui-input-inline" style="width: 200px;display:none"><select name="'+((resData.form_items[i].name[2] == undefined)?"county":resData.form_items[i].name[2])+'" title="'+resData.form_items[i].title+'" class="county-selector" data-value="'+((resData.form_items[i].value[2] == undefined)?"":resData.form_items[i].value[2])+'" lay-filter="county-'+i+'"></select></div>'+tips+'</div></div>';
                    html += '<script>layui.use(["layer","form","layarea"],function(){var layer=layui.layer,form=layui.form,layarea=layui.layarea;layarea.render({elem:"#area-picker-'+i+'",data: {province: "'+((resData.form_items[i].value[0] == undefined)?"":resData.form_items[i].value[0])+'",city: "'+((resData.form_items[i].value[1] == undefined)?"":resData.form_items[i].value[1])+'",county: "'+((resData.form_items[i].value[2] == undefined)?"":resData.form_items[i].value[2])+'",province_placeholder:"--选择省--", city_placeholder:"--选择省--",county_placeholder:"--选择区--"},change:function(res){}})});<\/script>';
                    break;
                //省市    
                case 'city':
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name.join("|")]==undefined?layout:resData.layout[resData.form_items[i].name.join("|")])+'" id="area-picker-'+i+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><div class="layui-input-inline" style="width: 200px;"><select name="'+((resData.form_items[i].name[0] == undefined)?"province":resData.form_items[i].name[0])+'" title="'+resData.form_items[i].title+'" class="province-selector" data-value="'+((resData.form_items[i].value[0] == undefined)?"":resData.form_items[i].value[0])+'" lay-filter="province-'+i+'"></select></div><div class="layui-input-inline" style="width: 200px;"><select name="'+((resData.form_items[i].name[1] == undefined)?"city":resData.form_items[i].name[1])+'" title="'+resData.form_items[i].title+'" class="city-selector" data-value="'+((resData.form_items[i].value[1] == undefined)?"":resData.form_items[i].value[1])+'" lay-filter="city-'+i+'"></select></div><div class="layui-input-inline" style="width: 200px;display:none"><select name="'+((resData.form_items[i].name[2] == undefined)?"county":resData.form_items[i].name[2])+'" title="'+resData.form_items[i].title+'" class="county-selector" data-value="'+((resData.form_items[i].value[2] == undefined)?"":resData.form_items[i].value[2])+'" lay-filter="county-'+i+'"></select></div>'+tips+'</div></div>';
                    html += '<script>layui.use(["layer","form","layarea"],function(){var layer=layui.layer,form=layui.form,layarea=layui.layarea;layarea.render({elem:"#area-picker-'+i+'",data: {province: "'+((resData.form_items[i].value[0] == undefined)?"":resData.form_items[i].value[0])+'",city: "'+((resData.form_items[i].value[1] == undefined)?"":resData.form_items[i].value[1])+'",county: "'+((resData.form_items[i].value[2] == undefined)?"":resData.form_items[i].value[2])+'",province_placeholder:"--选择省--", city_placeholder:"--选择省--",county_placeholder:"--选择区--"},change:function(res){}})});<\/script>';
                    break;        
                case 'checkbox':
                    var options = '';
                    for(var j=0; j<resData.form_items[i].options.length; j++){ 
                        var isCheck = "";
                        isCheck = in_array((resData.form_items[i].options[j].value).toString(),resData.form_items[i].value != ""?(resData.form_items[i].value).split(resData.form_items[i].delimiter):new Array())?'checked':'';
                        options += '<input type="checkbox" name="'+resData.form_items[i].name+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" title="'+resData.form_items[i].options[j].title+'"  autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" value="'+resData.form_items[i].options[j].value+'" lay-skin="'+resData.form_items[i].skin+'" '+isCheck+resData.form_items[i].extra_attr+'>'; 
                    }
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block" style="display: flex;flex-direction: row; justify-content: left;align-items: center;" id="checkbox-'+i+'">'+options+tips+'</div></div>';      
                    break;
                case 'radio':
                    var options = '';
                    for(var j=0; j<resData.form_items[i].options.length; j++){ 
                        var isCheck = "";
                        isCheck = (resData.form_items[i].options[j].value).toString() == resData.form_items[i].value ? 'checked' : '';
                        options += '<input type="radio" name="'+resData.form_items[i].name+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" title="'+resData.form_items[i].options[j].title+'"  autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" value="'+resData.form_items[i].options[j].value+'" lay-skin="'+resData.form_items[i].skin+'" '+isCheck+resData.form_items[i].extra_attr+'>'; 
                    }
          
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block">'+options+tips+'</div></div>';
                    break;    
                case 'year':
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><input id="datetime-'+i+'" type="text" name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" placeholder="'+resData.form_items[i].placeholder+'" autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" value="'+resData.form_items[i].value+'" '+resData.form_items[i].extra_attr+'>'+tips+'</div></div>';
                    html += '<script>layui.use("laydate", function(){var laydate = layui.laydate;laydate.render({elem: "#datetime-' + i + '",type: "year",calendar: true,theme: "'+resData.form_items[i].theme+'", trigger: "click",lang:"cn",min:"'+resData.form_items[i].min+'",max:"'+resData.form_items[i].max+'"});});<\/script>';
                    break; 
                case 'month':
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><input id="datetime-'+i+'" type="text" name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" placeholder="'+resData.form_items[i].placeholder+'" autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" value="'+resData.form_items[i].value+'" '+resData.form_items[i].extra_attr+'>'+tips+'</div></div>';
                    html += '<script>layui.use("laydate", function(){var laydate = layui.laydate;laydate.render({elem: "#datetime-' + i + '",type: "month",calendar: true,theme: "'+resData.form_items[i].theme+'", trigger: "click",lang:"cn",min:"'+resData.form_items[i].min+'",max:"'+resData.form_items[i].max+'"});});<\/script>';
                    break;     
                case 'date': 
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><input id="datetime-'+i+'" type="text" name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" placeholder="'+resData.form_items[i].placeholder+'" autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" value="'+resData.form_items[i].value+'" '+resData.form_items[i].extra_attr+'>'+tips+'</div></div>';
                    html += '<script>layui.use("laydate", function(){var laydate = layui.laydate;laydate.render({elem: "#datetime-' + i + '",type: "date",calendar: true,theme: "'+resData.form_items[i].theme+'", trigger: "click",lang:"cn",min:"'+resData.form_items[i].min+'",max:"'+resData.form_items[i].max+'"});});<\/script>';
                    break;   
                case 'time':
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><input id="datetime-'+i+'" type="text" name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" placeholder="'+resData.form_items[i].placeholder+'" autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" value="'+resData.form_items[i].value+'" '+resData.form_items[i].extra_attr+'>'+tips+'</div></div>';
                    html += '<script>layui.use("laydate", function(){var laydate = layui.laydate;laydate.render({elem: "#datetime-' + i + '",type: "time",calendar: true,theme: "'+resData.form_items[i].theme+'", trigger: "click",lang:"cn",min:"'+resData.form_items[i].min+'",max:"'+resData.form_items[i].max+'"});});<\/script>';
                    break; 
                case 'datetime':
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><input id="datetime-'+i+'" type="text" name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" placeholder="'+resData.form_items[i].placeholder+'" autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" value="'+resData.form_items[i].value+'" '+resData.form_items[i].extra_attr+'>'+tips+'</div></div>';
                    html += '<script>layui.use("laydate", function(){var laydate = layui.laydate;laydate.render({elem: "#datetime-' + i + '",type: "datetime",calendar: true,theme: "'+resData.form_items[i].theme+'", trigger: "click",lang:"cn",min:"'+resData.form_items[i].min+'",max:"'+resData.form_items[i].max+'"});});<\/script>';
                    break;  
                case 'select':
                    var options = '<option value="">' + resData.form_items[i].placeholder + '</option>';
                    for(var j=0; j<resData.form_items[i].options.length; j++){
                        var isDisable = '';
                        if(in_array(resData.form_items[i].options[j].value,resData.form_items[i].disableds)){
                            isDisable = "disabled";
                        } 
                        if(resData.form_items[i].options[j].value != undefined && (resData.form_items[i].options[j].value).toString() == (resData.form_items[i].value).toString()){
                            options += '<option value="' + resData.form_items[i].options[j]['value'] + '" '+isDisable+' selected>' + resData.form_items[i].options[j]['title'] + '</option>';
                        }else{
                            options += '<option value="' + resData.form_items[i].options[j]['value'] + '" '+isDisable+'>' + resData.form_items[i].options[j]['title'] + '</option>';
                        }
                    }
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><select name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" placeholder="'+resData.form_items[i].placeholder+'" autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" '+resData.form_items[i].extra_attr+'>'+options+'</select>'+tips+'</div></div>';
                    break; 
                case 'selectgroup':
                    var options = '<option value="">' + resData.form_items[i].placeholder + '</option>';
                    
                    for (var j = 0; j < resData.form_items[i].options.length; j++) {
                            // options += '<optgroup label="' + resData.form_items[i].options[j].title + '">';
                             //一级 
                            var isDisable = '';
                            if(in_array(resData.form_items[i].options[j].value,resData.form_items[i].disableds)){
                                isDisable = "disabled";
                            }  
                          
                            if (resData.form_items[i].options[j].value != undefined && (resData.form_items[i].options[j].value).toString() == (resData.form_items[i].value).toString()) {
                                options += '<option value="' + resData.form_items[i].options[j].value + '" '+isDisable+' selected>┌&nbsp;' + resData.form_items[i].options[j].title + ' </option>'
                            } else {
                                options += '<option value="' + resData.form_items[i].options[j].value + '" '+isDisable+'>┌&nbsp;' + resData.form_items[i].options[j].title + ' </option>'
                            }
                            
                            if(resData.form_items[i].options[j].options != undefined){
                                for (var k = 0; k < resData.form_items[i].options[j].options.length; k++) {
                                    var isDisable = '';
                                    if(in_array(resData.form_items[i].options[j].options[k].value,resData.form_items[i].disableds)){
                                        isDisable = "disabled";
                                    }
                                    //二级
                                    if (resData.form_items[i].options[j].options[k].value != undefined && (resData.form_items[i].options[j].options[k].value).toString() == (resData.form_items[i].value).toString()) {
                                        options += '<option value="' + resData.form_items[i].options[j].options[k].value +'" '+isDisable+' selected>&nbsp;●&nbsp;' + resData.form_items[i].options[j].options[k].title + ' </option>'
                                    } else {
                                        options += '<option value="' + resData.form_items[i].options[j].options[k].value + '" '+isDisable+'>&nbsp;●&nbsp;' + resData.form_items[i].options[j].options[k].title + ' </option>'
                                    }
                                    //三级
                                    if(resData.form_items[i].options[j].options[k].options != undefined){
                                        for (var n = 0; n < resData.form_items[i].options[j].options[k].options.length; n++) {
                                            var isDisable = '';
                                            if(in_array(resData.form_items[i].options[j].options[k].options[n].value,resData.form_items[i].disableds)){
                                                isDisable = "disabled";
                                            }
                                            if (resData.form_items[i].options[j].options[k].options[n].value != undefined && (resData.form_items[i].options[j].options[k].options[n].value).toString() == (resData.form_items[i].value).toString()) {
                                                options += '<option value="' + resData.form_items[i].options[j].options[k].options[n].value + '" '+isDisable+' selected>&nbsp;&nbsp;&nbsp;◇&nbsp;' + resData.form_items[i].options[j].options[k].options[n].title + ' </option>'
                                            } else {
                                                options += '<option value="' + resData.form_items[i].options[j].options[k].options[n].value + '" '+isDisable+'>&nbsp;&nbsp;&nbsp;◇&nbsp;' + resData.form_items[i].options[j].options[k].options[n].title + ' </option>'
                                            }
                                        }
                                    }
                                    
                                }
                            }
                            
                            // options += ' </optgroup>';
                        }
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block"><select name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" placeholder="'+resData.form_items[i].placeholder+'" autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" '+resData.form_items[i].extra_attr+'>'+options+'</select>'+tips+'</div></div>';
                    break;     
                    
                case 'file': 
                case 'files':
                    var fileHtml = '';
                        for(var j=0; j<resData.form_items[i].srcs['src'].length; j++){
                            var percent = "100%";
                            if(resData.form_items[i].srcs['sizes'][j] == 0){
                                percent = "0%";
                            }
                            fileHtml += '<tr id="upload-'+i+'-'+j+'"><td>'+resData.form_items[i].srcs['alt'][j]+'</td><td>'+convertFileSize(resData.form_items[i].srcs['sizes'][j])+'</td><td><div class="layui-progress" style="top:10px;" lay-showpercent="true" lay-filter="progress-'+i+'-'+j+'"><div class="layui-progress-bar"  lay-percent="100%" style="width: '+percent+';"><span class="layui-progress-text">'+percent+'</span></div></div></td><td class="file-msg-'+i+'-'+j+'"><span class="layui-btn layui-btn-xs layui-btn-danger del-file-'+i+'" data-id="'+resData.form_items[i].file_ids[j]+'">删除</span></td></tr>';
                        }
                
                    var content = '<div class="layui-upload"><button type="button" class="layui-btn layui-btn-normal" id="start-upload-'+i+'">文件上传</button><div class="layui-upload-list" style="max-width: 1000px;"><table class="layui-table"><colgroup><col><col width="150"><col width="200"><col width="200"></colgroup><thead><tr><th>文件名</th><th>大小</th><th>上传进度</th><th>操作</th></tr></thead><tbody id="file-list-'+i+'">'+fileHtml+'</tbody></table></div></div> '
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block">'+content+tips+'</div><input type="hidden" class="file-'+i+'" name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" placeholder="'+resData.form_items[i].placeholder+'" autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" value="'+resData.form_items[i].value+'" '+resData.form_items[i].extra_attr+'/></div>';

                   
                      
                    html += '<script>if(($(".file-'+i+'").val()).length>0){inputs = trimSpace(($(".file-'+i+'").val()).split(",")); };layui.use(["layer","element"],function(){var layer = layui.layer,$ = layui.$,element = layui.element;var md5,uploader = WebUploader.create({pick: {id:"#start-upload-'+i+'",multiple:false},fileVal:"file",/**设置文件上传域的name*/ method: "post",/**设置请求方式 【post get】*/sendAsBinary:false,/**二进制上传 ---php://input都为文件内容， 其他参数在$_GET数组中*/formData: {uid: "",module:"webupload"},swf: "__BUILDER__/ueditor/third-party/webuploader/Uploader.swf",/**flash插件*/chunked: true,/**开启分片*/ chunkSize: '+webConfig.chunkSize+',/**分片大小*/chunkRetry:'+webConfig.chunkRetry+',/**如果某个分片由于网络问题出错，允许自动重传多少次*/duplicate:true,/**去重， 根据文件名字、文件大小和最后修改时间来生成hash Key.*/threads:'+webConfig.threads+',/**上传并发数。允许同时最大上传进程数*/server: "'+web_require_url+'&action=webuploader",/**api接口*/runtimeOrder: "html5",/**设置启动顺序[html5->flash]**/accept: {title: "file",extensions: "'+webConfig.file_exts+'",mimeTypes: "'+resData.form_items[i].accepts+'"},auto:false, /**是否自动上传*/ disableGlobalDnd: true, /**禁掉全局的拖拽功能。这样不会出现图片拖进页面的时候，把图片打开。*/fileNumLimit: '+resData.form_items[i].limit_num+',/**单文件上传--验证文件总数量, 超出则不允许加入队列*/fileSizeLimit: '+webConfig.file_max_size+',/**文件总大小---验证文件总大小是否超出限制, 超出则不允许加入队列*/fileSingleSizeLimit: '+webConfig.file_max_size+',/**单个文件大小*/prepareNextFile:false,/**是否允许在文件传输时提前把下一个文件准备好*/ disableWidgets:""/**默认所有 Uploader.register 了的 widget 都会被加载，如果禁用某一部分，请通过此 option 指定黑名单*/}); /**文件加入队列之前*/uploader.on("beforeFileQueued",function (file) {var input = $(".file-'+i+'").val();var inputs = [];if(input.length>0){inputs = trimSpace(input.split(","));}if(inputs.length>='+resData.form_items[i].limit_num+'){layer.msg("文件数量超过限制数量：'+resData.form_items[i].limit_num+'",function(){});/**取消文件，如果没有上传，则需要传入file对象*/this.cancelFile( file );return false;}});/**文件加入队列*/uploader.on("fileQueued", function(file) {$("#file-list-'+i+'").append(\'<tr id="upload-'+i+'-\'+file.id+\'"><td>\'+file.name+\'</td><td>\'+ convertFileSize(file.size) +\'</td><td><div class="layui-progress" style="top:10px;" lay-showpercent="true" lay-filter="progress-'+i+'-\'+file.id+\'"><div class="layui-progress-bar"  lay-percent=""><span class="layui-progress-text"></span></div></div></td><td class="file-msg-'+i+'-\'+file.id+\'"><span class="animation" style="color:#01AAED">正在计算文件的md5...</span></td></tr>\');this.md5File(file).then(function(ret) { md5 = ret; $("#file-list-'+i+'").find(".file-msg-'+i+'-\"+file.id+\"").html("<span  class=\'animation2\' style=\'color:#01AAED;\'>正在进行分片上传...</span>"); uploader.upload(); }); });/**开始上传*/ uploader.on("startUpload",function () {});/**分片上传之前触发--可以设置一些参数*/ uploader.on("uploadBeforeSend",function (obj, data, headers) {data.md5 = md5;  Object.assign(headers, '+JSON.stringify(http.headers)+');});/**上传前最后一次触发【只触发一次】*/uploader.on("uploadStart",function (file) {});/**暂停上传*/ uploader.on("stopUpload",function () { });/**上传结束*/ uploader.on("uploadFinished",function () {}); /**上传响应*/ uploader.on("uploadAccept",function (obj,res) {var progress = Math.round((obj.chunk+1)/obj.chunks * 100) + "%"; if(res.code == 0){element.progress("progress-'+i+'-\"+res.data.id+\"", progress);}if(res.code==0 && res.data.file_id != 0){element.progress("progress-'+i+'-\"+res.data.id+\"", "100%");this.cancelFile( res.data.id ); $("#file-list-'+i+'").find(".file-msg-'+i+'-\"+res.data.id+\"").html("<span class=\' layui-btn layui-btn-xs layui-btn-danger del-file-'+i+' \' data-id=\'\"+res.data.file_id+\"\'>删除</span>"); /**去重写入start*/var input = $(".file-'+i+'").val();var inputs = [];if(input.length>0){inputs = trimSpace(input.split(","));}if(!in_array((res.data.file_id).toString(),inputs)){inputs.push(res.data.file_id);$(".file-'+i+'").val(inputs.join(","));}else{layer.msg("文件已在列表中，请勿重复上传！",function(){});$("#upload-'+i+'-\"+res.data.id+\"").remove();} /**去重写入end*/  } }); /**重置uploader时触发函数*/uploader.on("reset",function () {}); uploader.on( "all", function( type ) {}); /**上传失败*/uploader.on("uploadError",function (file, reason) {console.log(reason);});  /**上传成功*/uploader.on("uploadSuccess",function (file, response) {});  /**进程结束*/uploader.on("uploadComplete",function (file) { }); /**验证不通过**/uploader.on("error", function (type) {layui.use("layer",function () { var layer = layui.layer; if(type == "Q_EXCEED_NUM_LIMIT"){ layer.msg("文件数量大于1"); }if(type == "Q_EXCEED_SIZE_LIMIT"){ layer.msg("文件总大小超出");}if(type == "Q_TYPE_DENIED"){ layer.msg("文件类型不满足");} });});});/**数据操作-删除start*/$(".layui-upload-list").on("click",".del-file-'+i+'",function (e) { var id = $(this).attr("data-id");var input = $(".file-'+i+'").val();var inputs = [];if(input.length>0){inputs = trimSpace(input.split(","));}if(in_array(id,inputs)){$(".file-'+i+'").val(array_splice(inputs,id).join(","));$(this).parent("td").parent("tr").remove();}}); /**数据操作-删除end*/<\/script>';
                 
                    break; 
                case 'image':
                    var imgHtml = '';
                        for(var j=0; j<resData.form_items[i].srcs['thumb'].length; j++){
                            imgHtml += '<li class="fl imgWrap"><img onclick="javascript:layerFormImages(this);" alt="'+resData.form_items[i].srcs['alt'][j]+'" class="preview-'+i+'" _src="'+resData.form_items[i].srcs['src'][j]+'" src="'+resData.form_items[i].srcs['thumb'][j]+'"><div class="file-panel"><span class="cancel del-image-'+i+'" data-id="'+resData.form_items[i].img_ids[j]+'">删除</span></div></li>';
                        }
                    var content = '<div class="layui-upload"><button type="button" class="layui-btn" id="image-'+i+'">图片上传</button><blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;display:flex;flex-direction:column;"><div class="layui-upload-list" id="image-list-'+i+'">'+imgHtml+'</div></blockquote><input type="hidden" class="image-'+i+'" name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" placeholder="'+resData.form_items[i].placeholder+'" autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" value="'+resData.form_items[i].value+'" '+resData.form_items[i].extra_attr+'/></div>';
                    
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block">'+content+tips+'</div></div>';

                    html += '<script>layui.use(["upload","element","layer"],function(){var upload = layui.upload,layer=layui.layer;upload.render({elem:"#image-'+i+'",url:"'+img_require_url+'" ,acceptMime:"image/*" ,field:"upfile",auto:true,accept:"images",headers:'+JSON.stringify(http.headers)+',multiple:true,before:function(obj){layer.msg("正在上传中...");},done:function(res){layer.closeAll();$(".image-'+i+'").val(res.file_id);$("#image-list-'+i+'").html(\'<li class="fl imgWrap"><img onclick="javascript:layerFormImages(this);"  class="preview-'+i+'" src="\'+res.thumb_path+\'" _src="\'+res.url+\'" alt="\'+res.file_name+\'" ><div class="file-panel"><span class="cancel del-image-'+i+'" data-id="\'+res.file_id+\'">删除</span></div></li>\');}})});$(".layui-upload-list").on("click",".del-image-'+i+'",function (e) {var id = $(this).attr("data-id");var input = $(".image-'+i+'").val();var inputs = [];if(input.length>0){inputs = trimSpace(input.split(","));}if(in_array(id,inputs)){$(".image-'+i+'").val(array_splice(inputs,id).join(","));$(this).parent("div").parent("li").remove();}})<\/script>';
                        
                    break;
                case 'images':
                    var imgHtml = '';
                        for(var j=0; j<resData.form_items[i].srcs['thumb'].length; j++){
                            imgHtml += '<li class="fl imgWrap"><img onclick="javascript:layerFormImages(this);" alt="'+resData.form_items[i].srcs['alt'][j]+'" class="preview-'+i+'" _src="'+resData.form_items[i].srcs['src'][j]+'" src="'+resData.form_items[i].srcs['thumb'][j]+'"><div class="file-panel"><span class="cancel del-image-'+i+'" data-id="'+resData.form_items[i].img_ids[j]+'">删除</span></div></li>';
                        }
                    var content = '<div class="layui-upload"><button type="button" class="layui-btn" id="image-'+i+'">图片上传</button><blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;display:flex;flex-direction:column;"><div class="layui-upload-list" id="image-list-'+i+'">'+imgHtml+'</div></blockquote><input type="hidden" class="image-'+i+'" name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" placeholder="'+resData.form_items[i].placeholder+'" autocomplete="off" class="layui-input '+resData.form_items[i].extra_class+'" value="'+resData.form_items[i].value+'" '+resData.form_items[i].extra_attr+' /></div>';
                    
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block">'+content+tips+'</div></div>';

                    html += '<script>layui.use(["upload","element","layer"],function(){var upload = layui.upload,layer=layui.layer;upload.render({elem:"#image-'+i+'",url:"'+img_require_url+'" ,acceptMime:"image/*" ,field:"upfile",auto:true,accept:"images",headers:'+JSON.stringify(http.headers)+',multiple:true,before:function(obj){layer.msg("正在上传中...");},done:function(res){layer.closeAll();var inputs = [];if(($(".image-'+i+'").val()).length>0){inputs = trimSpace(($(".image-'+i+'").val()).split(",")); }/**去重写入图片--可以保证图片的顺序*/if(!in_array((res.file_id).toString(),inputs)){inputs.push(res.file_id);$("#image-list-'+i+'").append(\'<li class="fl imgWrap"><img onclick="javascript:layerFormImages(this);" class="preview-'+i+'" src="\'+res.thumb_path+\'" _src="\'+res.url+\'" alt="\'+res.file_name+\'" ><div class="file-panel"><span class="cancel del-image-'+i+'" data-id="\'+res.file_id+\'">删除</span></div></li>\');$(".image-'+i+'").val(inputs.join(","));}else{layer.msg("图片已在列表中，请勿重复上传！",function(){});};}});});$(".layui-upload-list").on("click",".del-image-'+i+'",function (e) {var id = $(this).attr("data-id");var input = $(".image-'+i+'").val();var inputs = [];if(input.length>0){inputs = trimSpace(input.split(","));}if(in_array(id,inputs)){$(".image-'+i+'").val(array_splice(inputs,id).join(","));$(this).parent("div").parent("li").remove();}})<\/script>';
                    break;             
                case 'ueditor':
                    var content = '<script id="editor-'+i+'" type="text/plain" name="'+resData.form_items[i].name+'" title="'+resData.form_items[i].title+'" lay-verify="'+resData.form_items[i].verify+'" lay-verType="'+resData.form_items[i].verType+'" autocomplete="off" class="'+resData.form_items[i].extra_class+'" '+resData.form_items[i].extra_attr+' >'+unescape_text(resData.form_items[i].value)+'<\/script>';
                    html += '<div class="layuiadmin-mb-15 '+(resData.layout[resData.form_items[i].name]==undefined?layout:resData.layout[resData.form_items[i].name])+'"><label class="layui-form-label">'+verify+resData.form_items[i].title+' ：</label><div class="layui-input-block">'+content+tips+'</div></div>';
                    html += '<script> var ue = UE.getEditor("editor-'+i+'");<\/script>';
                    break;                     
                default:
                    console.log("错误的构建的字段数据：" , resData.form_items[i]);
                    console.log("当前支持的构建的字段有：text|password|textarea|hidden|tag|cron|color_picker|icon|ueditor|address|checkbox|radio|year|month|date|time|datetime|select|selectgroup|file|files|image|images");
                    break;
            }
            
        }

        var btn = '<button class="layui-btn " lay-submit lay-filter="formUrl">立即提交</button>';
        if(resData.post_btn_disabled){
            btn = '<a href="javascript:;" class="layui-btn layui-btn-disabled">立即提交</a>'
        }
        html += '<div class="layui-form-item"><div class="layui-input-block">'+btn+'<button class="layui-btn layui-btn-primary" type="button" onclick="javascript:history.back(-1);return false;">返回上一步</button></div></div>';

       

        return html;
    }
</script>

<script>
//将文件大小进行转换
function convertFileSize(fileSize){
    if((fileSize/1024)<1024){
        return (fileSize/1024).toFixed(2) + "KB";
    }
    if((fileSize/(1024*1024))<1024){
        return (fileSize/(1024*1024)).toFixed(2) + "MB";
    }
    return (fileSize/(1024*1024*1024)).toFixed(2) + "GB";
}
//图片预览
function layerFormImages(othis,title){
    var data = [];
    var i = 0;
    var index = 0;//初始显示的序号
    $(othis).parent("li").parent(".layui-upload-list").children("li").each(function(){
        if($(this).children("img").attr("alt")==$(othis).attr("alt")){
            index = i;
        }
        data = data.concat({
                "alt": $(this).children("img").attr("alt"),
                "pid": i++, //图片id
                "src":$(this).children("img").attr("_src"), //原图地址
                "thumb": $(this).children("img").attr("src") //缩略图地址
            })
    });
    
//    console.log(data)
    layer.photos({
        photos: {
            "title": title==undefined?'图册':title, //相册标题
            "id": 0, //相册id
            "start": index, //初始显示的图片序号，默认0
            "data": data
        }, 
        anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
    });
}
</script>






   
    

